import { service } from './Request'
import qs from 'qs'

const carsApi = {
    // 创建车辆
    createCar(formData) {
        return service({
            url: "/cars",
            method: "post",
            data: formData,
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
    },

    // 获取车辆详情
    getCar(id) {
        return service({
            url: `/cars/${id}`,
            method: "get"
        })
    },

    // 更新车辆信息
    updateCar(id, formData) {
        return service({
            url: `/cars/${id}`,
            method: "put",
            data: formData,
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
    },

    // 删除车辆
    deleteCar(id) {
        return service({
            url: `/api/v1/cars/${id}`,
            method: "delete"
        })
    },

    // 获取车辆列表
    getCarList(params) {
        return service({
            url: "/cars",
            method: "get",
            params: params
        })
    },

    // 兼容原有API接口
    addData(params) {
        return service({
            url: "carInfo/car",
            method: "post",
            data: qs.stringify(params[1]),
            headers: {
                'Authorization': params[0]
            }
        })
    },

    getData(params) {
        return service({
            url: `/carInfo/car/${params[1]}`,
            method: "get",
            headers: {
                'Authorization': params[0]
            }
        })
    },

    editData(params) {
        return service({
            url: `/carInfo/car/${params[1]}`,
            method: "put",
            data: qs.stringify(params[2]),
            headers: {
                'Authorization': params[0]
            }
        })
    }
}

export default carsApi 